package com.meraklisina.latexeditor;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
*
* @author Ali Erkan
*/
public class AutoSave {
    
	private Boolean autoSaveClick;
	
    public AutoSave(){
    	autoSaveClick = false;
    }
    
    public Boolean getAutoSaveClick() {
    	return autoSaveClick;
    }
    
    public void setAutoSaveFalse(){
    	autoSaveClick = false;
    }
    
    public void setAutoSaveTrue(){
    	autoSaveClick = true;
    }
    
    public String getAutoSaveInterval(){
        try{
           FileReader fileReader = new FileReader("config.txt");
           BufferedReader bufferedReader = new BufferedReader( fileReader );
           String stringFromFile = bufferedReader.readLine();
           stringFromFile = bufferedReader.readLine();
           if (stringFromFile.contains("Auto")) {
        	   setAutoSaveTrue();
           } else {
        	   setAutoSaveFalse();
           }
           stringFromFile = bufferedReader.readLine();
           bufferedReader.close( );
           return stringFromFile;
        }catch(FileNotFoundException fileNotFoundException){
        	return ("Configuration file \"config.txt\" does not exist!\n");
        }catch(IOException ioexception){
          ioexception.printStackTrace();
          return ("An error occurred while reading \"config.txt\" ");
        }
    } 
}
